package com.sise.cn.task.config;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * @author 龚秀峰
 * @version 1.0
 * @date 2020/6/6 12:47
 * 全局校验配置类
 */
@Configuration
public class ValidationConfig {
    @Bean
    public Validator validator() {
        //校验出现失败则不继续校验
        ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure().failFast(true).buildValidatorFactory();
        Validator validator;
        validator = validatorFactory.getValidator();
        return validator;
    }
}
